package org.wtframework.platform.server.model.impl;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy;
import org.openredhead.springx.core.server.model.IResource;
import org.openredhead.springx.core.server.model.ISortObject;

@Entity
@Proxy(lazy = true)
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
@Table(name = "orh_sx_resource")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Resource implements IResource, ISortObject<Integer, Integer> {

	private static final long serialVersionUID = -1964438830638946060L;

	private Integer id;

	private String identifier;

	private String name;

	private String descn;

	private String url;

	private String method;

	private Integer orderId;

	private Integer parentId;

	private String image16;

	private String image24;

	private String image32;

	private String image48;

	private String image64;

	private String image128;

	// 是否敏感的信息
	private Boolean sensitivity = false;

	private String menuUrl; //菜单图片Url

	private List<Integer> childsId;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "order_id")
	public Integer getOrderId() {
		return orderId;
	}

	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	@Column(table = "orh_sx_resource", name = "parent_id")
	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "descn")
	public String getDescn() {
		return descn;
	}

	public void setDescn(String descn) {
		this.descn = descn;
	}

	@Column(name = "url_val")
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "method_val")
	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}


	@ElementCollection(fetch = FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	@JoinTable(name = "orh_sx_resource", joinColumns = @JoinColumn(name = "parent_id"))
	@Column(name = "child_id")
	public List<Integer> getChildsId() {
		return childsId;
	}

	public void setChildsId(List<Integer> childsId) {
		this.childsId = childsId;
	}

	@Column(name = "is_sensitivity")
	public Boolean getSensitivity() {
		return sensitivity;
	}

	public void setSensitivity(Boolean sensitivity) {
		this.sensitivity = sensitivity;
	}

	public String getIdentifier() {
		return identifier;
	}

	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	@Column(name = "menu_url")
	public String getMenuUrl() {
		return menuUrl;
	}

	
	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}
	

	@Column(name = "image_16")
	public String getImage16() {
		return image16;
	}

	public void setImage16(String image16) {
		this.image16 = image16;
	}

	@Column(name = "image_24")
	public String getImage24() {
		return image24;
	}

	public void setImage24(String image24) {
		this.image24 = image24;
	}

	@Column(name = "image_32")
	public String getImage32() {
		return image32;
	}

	public void setImage32(String image32) {
		this.image32 = image32;
	}

	@Column(name = "image_48")
	public String getImage48() {
		return image48;
	}

	public void setImage48(String image48) {
		this.image48 = image48;
	}

	@Column(name = "image_64")
	public String getImage64() {
		return image64;
	}

	public void setImage64(String image64) {
		this.image64 = image64;
	}

	@Column(name = "image_128")
	public String getImage128() {
		return image128;
	}

	public void setImage128(String image128) {
		this.image128 = image128;
	}


	@Override
	public boolean equals(Object o) {

		if (o == null) return false;

		if (!(o instanceof Resource)) return false;

		final Resource instance = (Resource) o;

		if (getId() != null ? !getId().equals(instance.getId()) : instance.getId() != null) return false;

		return true;

	}

	@Override
	public int hashCode() {

		return (getId() != null ? getId().hashCode() : 0);

	}
	
}
